# 3.3 PIR Motion Sensor ## 3.3.1 Overview The PIR motion sensor adopts RE200B-P element. Based on pyroelectric effect, the sensor is able to detect the infrared ray emitted by human body or animal. With Fresnel lens, it can even detect farther and wider. When a nearby human or animal motion is detected, the sensor outputs a high level. ## 3.3.2 Schematic Diagram ![t51](./media/t51.png) **Working principle:** The human body maintains at 37 degrees, so it will emit a specific wavelength of about 10μm infrared. The sensor captures 10μM infrared to determine whether there is a motion. ## 3.3.3 Code Blocks Blocks in ![](./media/control.png): 1. ![t52](./media/t52.png) “IF” block checks the Boolean condition. If it is true, the included blocks run once. ![t53](./media/t53.png) allows for expansions by adding multiple “ELSE IF” conditions. If the previous branches are not true, each of the following ELSE IF will be continuously evaluated and executed. -------------------- Blocks in ![](./media/codingBox.png): 1. ![t54](./media/t54.png) is a block included in coding box library. It reads the value of the PIR motion sensor in the coding box. When a person is detected, the sensor outputs a high level (1); when not, the sensor outputs a low level (0). ## 3.3.4 Test Code You can manually build blocks, or directly open the code file we provide: `3-3-Pir.ubp`. If you have any questions about how to open code files or upload code, please back to `1.9 Upload Code`. **Build code blocks:** 1. In ![](./media/control.png), drag ![](./media/t1.png) and ![](./media/t2.png) to the script area, and stack them together. ![t34](./media/t34.png) 2. In ![](./media/control.png), drag ![t52](./media/t52.png) block and put it in ![](./media/t2.png); Click ![t53](./media/t53.png) to add an “else”. ![t55](./media/t55.png) 3. In ![](./media/codingBox.png), drag ![t54](./media/t54.png) block and put it in ![t56](./media/t56.png). ![t57](./media/t57.png) 4. In ![](./media/output.png), drag two ![t44](./media/t44.png) and put them in ![t56](./media/t56.png) respectively. Output `Someone!` in “if” and `No one!` in “else”. **Complete code:** ![t58](./media/t58.png) ## 3.3.5 Test Result Connect the coding box to the MicroBlocks via USB or Bluetooth, and click ![t59](./media/t59.png) to upload the code to the coding box. When the PIR motion sensor detects a human, it outputs `Someone!`. If not, it shows `No one!`. ![t60](./media/t60.png)